<?php
	$xml_file = file_get_contents('http://bank-ua.com/export/currrate.xml');
		$xml = simplexml_load_string($xml_file);
		
		foreach ($xml as $xml_element) {
			if ($xml_element->char3 == "USD") {
				$USD_RATE = $xml_element->rate;				
			}
			
			if ( isset($USD_RATE) ) 
			{	break;	}
		} 
		
		if ( isset($USD_RATE) ) 
		{
			$filename = 'usd.txt';			
			$file = fopen($filename, 'w+');
			//if(is_writable($file))
			fwrite($file, $USD_RATE);
			fclose($file);
		}	
		else $this->err = true;	
?>